package com.ru.application.creditscore.bean;

import java.util.HashMap;
import javax.faces.component.UICommand;
import com.ru.application.creditscore.util.Constant;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

public class ToolbarBean {
    
    private UICommand button; 
    private HashMap<String, String> toolBar;
    private boolean enableSchema;
    private boolean enableFactor;
    private boolean enableSeperate;
    
    public ToolbarBean() {

    }
   
    public UICommand getButton() {
        return button;
    }


    public void setButton(UICommand button) {
        this.button = button;
    }

    public boolean isEnableSchema() {
	return enableSchema;
    }
    
    public boolean isEnableFactor() {
	return enableFactor;
    }
    
    public boolean isEnableSeperate() {
	return enableSeperate;
    }
    
    public void setEnableSchema(boolean enableSchema) {
        this.enableSchema = enableSchema;
    }


    public void setEnableFactor(boolean enableFactor) {
        this.enableFactor = enableFactor;
    }


    public void setEnableSeperate(boolean enableSeperate) {
        this.enableSeperate = enableSeperate;
    }


    public HashMap<String, String> getToolBar() {
        return toolBar;
    }

    public void setToolBar(HashMap<String, String> toolBar) {
        this.toolBar = toolBar;
    }
    
    public String click() {
	String result = Constant.HOME;
	String id = this.button.getId();
	HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false);
	if(id.compareToIgnoreCase(Constant.SCHEMA) == 0) {
	    this.setEnableSchema(false);
	    this.setEnableSeperate(false);
	    result = Constant.SCHEMA;
	    if(session != null) {
		session.removeAttribute(Constant.FACTOR);
	    }
	} else if(id.compareToIgnoreCase(Constant.FACTOR) == 0) {
	    this.setEnableFactor(false);
	    this.setEnableSeperate(false);
	    result = Constant.FACTOR;
	    if(session != null) { 
		session.removeAttribute(Constant.SCHEMA);
	    }
	} else {
	    this.setEnableFactor(true);
	    this.setEnableSeperate(true);
	    result = Constant.HOME;
	}
	return result;
    }
}
